-
Notifications
You must be signed in to change notification settings - Fork 307
🐛(i18n/backend) Fix/email in receiving user language #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛(i18n/backend) Fix/email in receiving user language #401
Conversation
c645b5b
to
72b5272
Compare
62ebf55
to
332e770
Compare
@sampaccoud |
fef3dea
to
3b3e90c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good !
A few comments.
@sampaccoud Should we add a migration to make all our current users french by default, because they will all switch to english after that, wdyt ?
src/frontend/apps/impress/src/features/language/api/useChangeUserLanguage.tsx
Outdated
Show resolved
Hide resolved
src/frontend/apps/impress/src/features/language/api/useChangeUserLanguage.tsx
Outdated
Show resolved
Hide resolved
b3534d3
to
704550b
Compare
704550b
to
d9bad8c
Compare
src/frontend/apps/impress/src/features/language/LanguagePicker.tsx
Outdated
Show resolved
Hide resolved
d9bad8c
to
f773350
Compare
1b5eb7b
to
38639c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Good job, works perfect ^^
I think Sam wants to have a look at it before merging.
I was expecting the language to be set on the user on first logging here: Otherwise how and when is this field set on the user? 🤔 |
src/backend/core/tests/documents/test_api_document_invitations.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments but it seems good to me, all seems working fine.
We try to not mix backend and frontend in the same commit, to be easier for reviewers, some of us are specialized in backend, other in front.
const [response] = await Promise.all([ | ||
page.waitForResponse( | ||
(resp) => | ||
resp.url().includes('/user') && resp.request().method() === 'PATCH', | ||
), | ||
page.getByLabel(lang.label).click(), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [response] = await Promise.all([ | |
page.waitForResponse( | |
(resp) => | |
resp.url().includes('/user') && resp.request().method() === 'PATCH', | |
), | |
page.getByLabel(lang.label).click(), | |
]); | |
const response = page.waitForResponse( | |
(resp) => | |
resp.url().includes('/user') && resp.request().method() === 'PATCH', | |
); | |
await page.getByLabel(lang.label).click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
const defaultQueries = [ | ||
{ | ||
icon: 'apps', | ||
label: t('All docs'), | ||
targetQuery: DocDefaultFilter.ALL_DOCS, | ||
}, | ||
{ | ||
icon: 'lock', | ||
label: t('My docs'), | ||
targetQuery: DocDefaultFilter.MY_DOCS, | ||
}, | ||
{ | ||
icon: 'group', | ||
label: t('Shared with me'), | ||
targetQuery: DocDefaultFilter.SHARED_WITH_ME, | ||
}, | ||
]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of useMemo is dicutable, but is this change necessary ? It seems to work correctly on my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function t
was not changing, when language was updated automatically to whatever is defined on the user.
Not sure why it happens, seems to be an issue of async nature.
Here is how you can reproduce it:
test.afterEach(async ({ page }) => { | ||
// Switch back to English - important for other tests to run as expected | ||
await waitForLanguageSwitch(page, TestLanguage.English); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add it to the top ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
@@ -41,7 +41,10 @@ export function AppProvider({ children }: { children: React.ReactNode }) { | |||
<QueryClientProvider client={queryClient}> | |||
<CunninghamProvider theme={theme}> | |||
<ConfigProvider> | |||
<Auth>{children}</Auth> | |||
<Auth> | |||
<LanguageInitializer /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add it in the ConfigProvider, it seems more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure?
I need auth to access the language of the user, logic in ConfigProvider does not need auth (yet)
It will add quite a bit of bloat to the ConfigProvider, better to have everything encapsulated in components and use them where they are needed right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can work if i make LanguageInitializer an async hook as you suggested below.
working on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
@@ -0,0 +1,66 @@ | |||
import i18n from 'i18next'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to get it like that:
import { useTranslation } from 'react-i18next';
...
const { i18n } = useTranslation();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
|
||
import { getMatchingLocales } from './utils/locale'; | ||
|
||
const LanguageInitializer = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the component doesn't have any content, better to make it as a hook, wdyt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
ffe4ad4
to
40d8831
Compare
40d8831
to
a313c91
Compare
- language for invitation emails => language saved on the invited user - if invited user does not exist yet => language of the sending user - if for some reason no sending user => system default language
- language for invitation emails => language saved on the invited user - if invited user does not exist yet => language of the sending user - if for some reason no sending user => system default language
a313c91
to
70704d7
Compare
70704d7
to
b0a5b71
Compare
- allow the language on the user to be unset - set the default language to be unset - helps us determine that the user has yet to set a language preference
- allow the language attribute on the user to be updated via API - add frontend function to update the user language via API - extend defaults on the test users, to have fixed language in E2E tests - extend types and variables using the types with the new field
- allow the language attribute on the user to be updated via API - add frontend function to update the user language via API - extend defaults on the test users, to have fixed language in E2E tests - extend types and variables using the types with the new field
- Adds a helper for working with locales - More details in their annotations - Unnecessary, if in the future, the backend uses the same locales as the keys in the translations (ISO 639-1)
- config endpoint languages are used as available options for LanguagePicker - updating the language from it, triggers an update on the user via API
- config endpoint languages are used as available options for LanguagePicker - updating the language from it, triggers an update on the user via API
- ensure editor is translated to i18n.resolvedLanguage => en as i18n.language could hold more accurate locale => en-GB etc..
- adds useLanguageSynchronizer hook to update the: 1. frontend-language to the user-preference - if there is one. 2. user-preference to the (browser-detected) frontend-language - otherwise.
- fixes a bug where after language-sync the left panel would remain in the same language as before.
- adds tests and test-utility for solid language switching in tests - fixes where ...getByRole(menuitem... would not return a valid object
b0a5b71
to
2419c26
Compare
@sampaccoud could you approve and merge ? |
@rvveber Amazing fix! Thanks for that Robin 💪 🎉 |
Implements the following:
Closes #323